import React, { Component } from 'react'
import { Redirect, Route } from 'react-router-dom'
import { isAuth } from '../../utils'

export default class AuthRoute extends Component {
  render() {
    // rest 剩余参数
    const { component: Component, ...rest } = this.props;
    return <Route {...rest} render={ props => 
      isAuth() ? <Component {...props} /> : 
      <Redirect to={{ 
        pathname: '/login', 
        state: { from: props.location }
      }} /> 
  }/>
  }
}
